@echo off
chcp 65001
echo Starting ELM Microservice Project Docker Deployment...

REM Check if Docker is installed
docker --version >nul 2>&1
if errorlevel 1 (
    echo Error: Docker is not installed, please install Docker first
    pause
    exit /b 1
)

REM Check if Docker Compose is installed
docker-compose --version >nul 2>&1
if errorlevel 1 (
    echo Error: Docker Compose is not installed, please install Docker Compose first
    pause
    exit /b 1
)

REM Stop and remove existing containers
echo Stopping existing containers...
docker-compose down

REM Ask if delete existing images
set /p delete_images="Delete existing images? (y/n): "
if /i "%delete_images%"=="y" (
    echo Deleting existing images...
    docker-compose down --rmi all
)

REM Build and start services
echo Building and starting services...
docker-compose up --build -d

REM Wait for services to start
echo Waiting for services to start...
timeout /t 30 /nobreak >nul

REM Check service status
echo Checking service status...
docker-compose ps

REM Show logs
echo Showing service logs...
docker-compose logs --tail=50

echo.
echo Deployment completed!
echo Access URLs:
echo - Eureka Registry: http://localhost:18000
echo - Gateway: http://localhost:12000
echo - User Service: http://localhost:8000
echo - MySQL: localhost:3306
echo.
pause 